package com.lanzhou.yuanfen.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.concurrent.ConcurrentHashMap;


/**
 * @author Administrator
 */
@Slf4j
@WebListener
public class MyApplicationListener implements ServletContextListener {


    @Override
    public void contextInitialized(ServletContextEvent sce) {
        log.debug("limiting: contextInitialized");
        log.debug("MyApplicationListener初始化成功");
        ServletContext context = sce.getServletContext();
        // IP存储器
        ConcurrentHashMap<String, Long[]> ipMap = new ConcurrentHashMap<>();
        context.setAttribute("ipMap", ipMap);
        // 限制IP存储器：存储被限制的IP信息
        ConcurrentHashMap<String, Long> limitedIpMap = new ConcurrentHashMap<>();
        context.setAttribute("limitedIpMap", limitedIpMap);
        log.debug("ipMap：" + ipMap.toString() + ";limitedIpMap:" + limitedIpMap.toString() + "初始化成功。。。。。");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        // TODO Auto-generated method stub
    }

}
